package com.example.gyj.controller;

import com.example.gyj.result.Result;
import com.example.gyj.service.LoginService;
import com.example.gyj.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * Created by Gao on 2018/10/20.
 */
@Controller
@RequestMapping(value = "/login")
public class LoginController {

    private static Logger log = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private LoginService loginService;

    @RequestMapping(value = "/toLogin")
    public String toLogin() {
        return "login";  //thymeleaf 能够加载静态页面, 指定路径
    }

    @RequestMapping("/login.do")
    @ResponseBody
    public Result<String> login(HttpServletResponse response, @Valid LoginVo loginVo) {
        log.info(loginVo.toString());
        String token = loginService.login(response, loginVo);

        return Result.success(token);
    }
}
